package com.deanlib.cabinet.ui.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

/**
 * 底部展示的 dialog
 * Created by Dean on 2021/7/12
 */
public class BottomFullDialog extends Dialog {
    public BottomFullDialog(Context context) {
        super(context);
    }

    public BottomFullDialog(Context context,View contentView, int themeResId) {
        super(context, themeResId);


        requestWindowFeature(Window.FEATURE_NO_TITLE);
        contentView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                BottomFullDialog.this.dismiss();
                return true;
            }
        });
        super.setContentView(contentView);
    }

    protected BottomFullDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setGravity(Gravity.BOTTOM);//设置显示在底部
        WindowManager windowManager=getWindow().getWindowManager();
        Display display= windowManager.getDefaultDisplay();
        WindowManager.LayoutParams layoutParams=getWindow().getAttributes();
        layoutParams.width=display.getWidth();//设置Dialog的宽度为屏幕宽度
        getWindow().setAttributes(layoutParams);
    }

}
